<?php

namespace App\Models;



class CzChannel extends ApiBaseModel
{

    protected $table = 'cz_channel';
    protected $fillable = [
        'channel_name',
        'channel_code',
        'status',
        'setting',
        'callback_type',
        'callback_url',
        'is_sync',
        'balance',
        'credit',
        'msg',
        'backParams',
        'create_by',
        'update_by',
    ];
    protected $casts = [
        'status' => 'string',
    ];

    public function getSettingAttribute($value)
    {
        return unserialize($value);
    }
    public function setSettingAttribute($value)
    {
        $this->attributes['setting'] = serialize($value);
    }
    public function getCallbackUrlAttribute($value)
    {
        //        return env('APP_URL')."/callback.php?c={$this->attributes['channel_code']}&id={$this->attributes['id']}";
        return env('APP_URL') . "/callback.php/{$this->attributes['channel_code']}/{$this->attributes['id']}";
    }
    public function channel_order()
    {
        return $this->belongsTo(ChannelOrder::class, 'id', 'channel_id');
    }
}
